package cn.Y_Qiu.pay.service.impl;

import cn.Y_Qiu.basic.exception.BusinessException;
import cn.Y_Qiu.basic.service.impl.BaseServiceImpl;
import cn.Y_Qiu.order.service.IProductOrderService;
import cn.Y_Qiu.pay.domain.AlipayInfo;
import cn.Y_Qiu.pay.domain.PayBill;
import cn.Y_Qiu.pay.mapper.AlipayInfoMapper;
import cn.Y_Qiu.pay.mapper.PayBillMapper;
import cn.Y_Qiu.pay.service.IPayBillService;
import cn.Y_Qiu.pay.utils.AlipayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Autowired
    private AlipayInfoMapper alipayInfoMapper;

    @Autowired
    private PayBillMapper payBillMapper;

    @Autowired
    private IProductOrderService productOrderService;


    @Override
    public String request(PayBill bill) {
        if (bill == null){
            throw new BusinessException("参数空");
        }
        PayBill bill1 = payBillMapper.queryById(bill.getId());
        if (bill1 == null){
            throw new BusinessException("不存在的订单");
        }
        switch (bill.getPayChannel().intValue()){
            case 1:
                AlipayInfo info = alipayInfoMapper.loadByShopId(bill.getShop_id());
                return AlipayUtil.AliPayUtil(info, bill);
        }
        return null;
    }

    @Override
    public PayBill loadByUnionPaySn(String unionPaySn) {
        return payBillMapper.loadByUnionPaySn(unionPaySn);
    }
}
